from nl2sql.prompt.Sql_Fixer_Prompt import sql_fixer_prompt
from nl2sql.model.llm import  LLM
from nl2sql.tools.extract_block import extract_sql
class SqlFixer:
    def __init__(self,


                model_name = "deepseek-v3",
                api_key = "sk-68ac5f5ccf3540ba834deeeaecb48987",
                base_url = "https://dashscope.aliyuncs.com/compatible-mode/v1"
                 ) -> None:
        """
        :param model: 模型的名称
        :param api_key:
        :param base_url:
        """



        self.prompt = sql_fixer_prompt

        self.llm = LLM(
        model_name=model_name,
        api_key=api_key,
        base_url=base_url,
        temperature=0.5,  # 使用较低温度以获得更确定的输出
        max_tokens=1024
    )

    def fix_sql(self, data_info:str,  query:str, sql:str) -> str:
        """
        用于拆解用户的问题，为子问题
        :param query:
        :return: None or List of String
        """
        # 把Prompt模板，进行填充
        filled_prompt = self.prompt.format(data_info=data_info, query=query, sql=sql)
        # 让大模型对填充好的模板，进行推理
        result = self.llm.chat(filled_prompt)
        return result

